<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">

            <div class="layui-card-body cardbody">
              <div class="layui-form" lay-filter="">

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">应用名称</label>
                    <div class="layui-input-inline">
                      <input type="text" name="applyName" placeholder="请输入名称" autocomplete="off" class="layui-input"
                        v-model="itemData.applyName">
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">AppID</label>
                    <div class="layui-input-inline">
                      <input type="text" name="appId" placeholder="请输入ID" autocomplete="off" class="layui-input"
                        v-model="itemData.appId">
                    </div>
                    <span class="notes">小程序ID:例如:wxbf461a18c584e8b7</span>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">秘钥</label>
                    <div class="layui-input-inline">
                      <input type="text" name="appSecret" placeholder="请输入秘钥" autocomplete="off" class="layui-input"
                        v-model="itemData.appSecret">
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">logo</label>
                  <div class="layui-input-inline">
                    <div class="layui-upload">
                      <button type="button" class="layui-btn" id="test1">上传图片</button>
                      <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1"
                          :src="itemData.logo?itemData.logo:'http://kedoujfpc.tongdui365.com/static/common/image/zwyl.jpg'"
                          width="100" height="100" style="border:1px solid #eee;">
                        <p id="demoText1"></p>
                      </div>
                    </div>
                  </div>
                  <span class="notes">*上传大小不超过1M，长宽等比且范围在50px至200px之间的png格式图片</span>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">界面图片</label>
                  <div class="layui-input-inline">
                    <div class="layui-upload">
                      <button type="button" class="layui-btn" id="test2">上传界面</button>
                      <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo2"
                          :src="itemData.interfaceImage?itemData.interfaceImage:'http://kedoujfpc.tongdui365.com/static/common/image/zwyl.jpg'"
                          width="100" height="100" style="border:1px solid #eee;">
                        <p id="demoText2"></p>
                      </div>
                    </div>
                  </div>
                  <span
                    class="notes">必传尺寸为1080*1920（长1720px-2120px之间，宽880px-1280px之间）系统将智能适配640*1136、640*960、1536*2048、800*1280、720*1280、400*800等分辨率的机型，以帮助你快速创建应用。</span>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">是否直播 </label>
                  <div class="layui-input-inline">
                    <select name="liveOpenStatus" lay-filter="liveOpenStatus" v-model="itemData.liveOpenStatus">
                      <option value="YES">开启</option>
                      <option value="NO">关闭</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button class="layui-btn  layui-btn-normal" lay-submit @click="sure">确认</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: 'shopsetem',
  data () {
    return {
      id: "",
      itemData: {
        applyName: '',//应用名称
        appId: '',// appID
        appSecret: '',// 秘钥
        interfaceImage: '',//界面图片
        liveOpenStatus: '', //是否开启直播
        logo: '', // logo
        auditStatus: 'UNAUDITED',
      }
    }
  },
  mounted () {
    var vm = this;
    window.getdates = this.getdates;
    layui.use("upload", function () {
      var upload = layui.upload;
      var uploadInst = upload.render({
        elem: "#test1", //绑定元素
        data: {
          type: 3
        }
        , url:imguploadurl//上传接口
        , done: function (res) {
          layer.msg('上传成功');
          vm.itemData.logo = res.msg;
        }
        , error: function () {
          layer.msg('上传失败');
        }
      });
      upload.render({
        elem: "#test2", //绑定元素
        data: {
          type: 3
        }
        , url: imguploadurl //上传接口
        , done: function (res) {
          layer.msg('上传成功');
          vm.itemData.interfaceImage = res.msg;
        }
        , error: function () {
          layer.msg('上传失败');
        }
      });

    });

  },
  methods: {
    getdates: function (data) {
      var vm = this;
      vm.itemData.id=data.id
      var url = "/advert/bapi/v1.9/apply-setting/byDealer/apply";
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        if (ret.data != null) {
          vm.itemData = ret.data;
        }
      });
    },
    sure: function () {
      var vm = this;
      // var tid = "POST";
      var dates = this.itemData;
      // this.id = dates.id;
      // if (this.id) {
      //   dates.id = this.id;
      //   tid = "PUT";
      // }
      var url = "/advert/bapi/v1.9/apply-setting";
      ajaxRequest(url, "POST", "json", dates, function (ret, err) {
        layer.msg("操作成功");
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
          parent.location.reload();
        }, 1000);
      });
    },
  },
  updated: function () {
    var vm = this;
    layui.use('form', function () {
      var form = layui.form;
      form.render();
      form.on("select(liveOpenStatus)", function (data) {
        vm.itemData.liveOpenStatus = data.value;
      });
    });

  },
}
</script>
<style scoped>
.notes {
  color: #999;
}
.layui-form-label {
  font-size: 15px;
}
</style>